﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace LostLib.IO
{
	public static class StreamExtensions
	{
		public static void Transfer<S, D>(this S source, D dest, int bufferSize)
			where S : Stream
			where D : Stream
		{
			byte[] buffer = new byte[bufferSize];
			int read;
			do
			{
				read = source.Read(buffer, 0, bufferSize);
				if (read > 0)
					dest.Write(buffer, 0, read);
			} while (read > 0);
		}

		public static void Transfer<S, D>(this S source, D dest)
			where S : Stream
			where D : Stream
		{
			source.Transfer(dest, 64 * 1024);
		}
	}
}
